#include "ether_decoder.h"

EtherDecoder::EtherDecoder()
{
	pEtherHead = NULL;
}

EtherDecoder::EtherDecoder(const u_char* packetcontent)
{
	pEtherHead = (struct ether_header *)packetcontent;
}

EtherDecoder::~EtherDecoder()
{
	pEtherHead = NULL;
	delete pEtherHead;
}

string EtherDecoder::GetDstHost()
{
	return hostHEX(pEtherHead->ether_dhost);
}

string EtherDecoder::GetSrcHost()
{
	return hostHEX(pEtherHead->ether_shost);
}

unsigned int EtherDecoder::GetEtherType()
{
	return pEtherHead->ether_type;
}

ether_header* EtherDecoder::GetEtherHead()
{
	return pEtherHead;
}


string EtherDecoder::hostHEX(unsigned char input[])
{
	char buff[8];
	string tmp = "";
	for (int j=0;j<ETH_ALEN;j++)
	{
		itoa((int)input[j],buff,16);
		
		tmp+=(string)buff;
		if (j<5)
		{
			tmp+=":";
		}
	}
	return tmp;
}